package com.controller.stu;

import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.enterprise.inject.New;

import org.omg.CORBA.DATA_CONVERSION;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.model.Thesistitle;
import com.model.Thesisprogressrecord;

public class thesisprogressrecordController extends Controller{
	
	/**
	 * 进展记录页面
	 */
	public void index()
	{
//		String stuNumber = getSessionAttr("studentId");//获取学生学号
		int stuId=getSessionAttr("stuNum");
		setAttr("stu_tch", Thesisprogressrecord.dao.index(stuId));
		render("/pages1/stu_5.jsp");
	}
	
	/**
	 * 进展记录列表
	 */
	public void table()
	{
		System.out.println("*******************进展记录表格*******************");
//		String stuNumber = getSessionAttr("studentId");//获取学生学号
		String stuNumber = "04120802";
		int stuId=getSessionAttr("stuNum");
		System.out.println("学号："+stuNumber);
		System.out.println("id："+stuId);
		Integer page = getParaToInt("page");
		Integer rows = getParaToInt("rows");
		System.out.println("*******************进展记录结束*******************");
		renderJson(Thesisprogressrecord.dao.table(page, rows, stuId));
	}
	
	/**
	 * 添加新进展记录
	 * @throws UnsupportedEncodingException
	 */
	public void save() throws UnsupportedEncodingException 
	{
		System.out.println("*******************添加进展记录*******************");
//		String stuNumber = getSessionAttr("studentId");
		boolean success=false;
		String stuNumber = "04120802";
		int stuId=getSessionAttr("stuNum");
		System.out.println("学号："+stuNumber);
		System.out.println("id："+stuId);
		String text = new String(getPara("text").getBytes("iso8859-1"),"utf-8");
		success=Thesisprogressrecord.dao.save(stuId, text);
		System.out.println("*******************添加进展记录结束*******************");
		renderJson("{\"success\":"+success +"}");
	}
	
	/**
	 * 显示需要修改的进展记录信息
	 */
	public void edit()
	{
		System.out.println("*******************修改进展记录*******************");
		int prorec_id=getParaToInt("id");
		System.out.println("进展记录id："+getPara("id"));
		System.out.println("*******************修改进展记录结束*******************");
//		render("/view/text.jsp");
		renderJson(Thesisprogressrecord.dao.edit(prorec_id));
	}
	
	/**
	 * 删除对应id进展记录
	 */
	public void delete()
	{
		System.out.println("*******************删除进展记录*******************");
		boolean success=false;
		int prorec_id=Integer.parseInt(getPara("id"));
		System.out.println("进展记录id："+getPara("id"));
		success=Thesisprogressrecord.dao.deleteById(prorec_id);
		System.out.println("*******************删除进展记录结束*******************");
		renderJson("{\"success\":"+success+"}");
	}
	
	/**
	 * 更新相应进展记录信息
	 * @throws UnsupportedEncodingException
	 */
	public void updata() throws UnsupportedEncodingException 
	{
		boolean success=false;
		System.out.println("*******************更新进展记录*******************");
		int prorec_id=Integer.parseInt(getPara("id"));
		System.out.println("进展记录id："+getPara("id"));
		String text = new String(getPara("text").getBytes("iso8859-1"),"utf-8");
		success=Thesisprogressrecord.dao.update(prorec_id, text);
		System.out.println("*******************更新进展记录结束*******************");
		renderJson("{\"success\":"+success+"}");
	}
	
	
}
